﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.general.mytable;
using Webdiver;


namespace AnyOffice.general.news.show
{
    public partial class index1 : ModulePage
    {
    

        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        private void BindData()
        {
            DataTable table = new NewsDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false, Convert.ToInt32(this.ViewState["TypeId"].ToString()));
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            this.rptNews.DataSource = table;
            this.rptNews.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条简报";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int typeId = (Request.QueryString["type_id"] != null) ? int.Parse(Request.QueryString["type_id"].ToString()) : 0;
                this.ViewState["TypeId"] = typeId;
                DataTable table = new NewsTypeDao().SelectAll(base.Conn);
                this.ddlTypeId.DataSource = table;
                this.ddlTypeId.DataBind();
                this.ddlTypeId.Items.Insert(0, new ListItem("全部类型", "0"));
                this.ddlTypeId.Attributes.Add("onchange", "change_type(this.value);");
                if (this.ddlTypeId.Items.FindByValue(typeId.ToString()) != null)
                {
                    this.ddlTypeId.Items.FindByValue(typeId.ToString()).Selected = true;
                }
                this.AspNetPager1.PageSize = new ConfigManager().PageSize;
             

                DataTable table2 = new NewsDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true, typeId);
                if (int.Parse(table2.Rows[0][0].ToString()) == 0)
                {
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无已发布的新闻");
                }
                else
                {
                    this.AspNetPager1.RecordCount = int.Parse(table2.Rows[0][0].ToString());
                    this.BindData();
                }


            }
        }
    }
}
